
#include "service.hpp"
#include "service_tcp.hpp"
#include "service_udp.hpp"

service::~service()
{
  delete _tcp;
  delete _udp;
}


service::service()
  : _mux(0)
  , _tcp(new service_tcp)
  , _udp(new service_udp)
{
}

void service::initialize(am::imux<>* mux, ihitlist* hl)
{
  _mux = mux;
  _tcp->get_prototype().get_aspect().get<_hit_>().hitlist = hl;
  _tcp->get_prototype().get_aspect().get<_hit_counts_>().hitlist = hl;
  _tcp->get_prototype().get_aspect().get<_hitlist_>().hitlist = hl;
  _udp->get_prototype().get_aspect().get<_hit_>().hitlist = hl;
}

void service::tcp_start(const std::string& addr, unsigned short port)
{
  _tcp->set_mux(_mux);
  _tcp->set_nonblock(true);
  _tcp->start(addr, port);
}

void service::udp_start(const std::string& addr, unsigned short port)
{
  _udp->set_mux(_mux);
  _udp->set_nonblock(true);
  _udp->start(addr, port);
}

